package com.emm.yixun.mobile.adapter;

import android.content.Context;
import android.graphics.Color;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.ImageView;
import android.widget.TextView;

import com.emm.yixun.mobile.R;
import com.emm.yixun.mobile.model.GetProjectList;

public class MainProjectAdapter extends BaseAdapter {

	Context context;

	GetProjectList list;

	int type = 0;

	public MainProjectAdapter(Context context, GetProjectList list) {
		this.context = context;
		this.list = list;
	}

	public void SeleCt(int postion) {
		for (int i = 0; i < list.getProjectList().size(); i++) {
			list.getProjectList().get(i).setSelect(false);
		}
		try {
			list.getProjectList().get(postion).setSelect(true);
		} catch (IndexOutOfBoundsException e) {
		}
		notifyDataSetChanged();
	}

	public void SetType(int type) {
		this.type = type;
		notifyDataSetChanged();
	}

	@Override
	public int getCount() {
		return list.getProjectList() == null ? 0 : list.getProjectList().size();
	}

	@Override
	public Object getItem(int position) {
		return list.getProjectList() == null ? null : list.getProjectList().get(position);
	}

	@Override
	public long getItemId(int position) {
		return position;
	}

	@Override
	public View getView(int position, View convertView, ViewGroup parent) {
		ViewHodler v = null;
		if (convertView == null) {
			convertView = LayoutInflater.from(context).inflate(R.layout.mainproject_item, null);
			v = new ViewHodler();
			v.content = (TextView) convertView.findViewById(R.id.content);
			v.icon1 = (ImageView) convertView.findViewById(R.id.icon1);
			v.icon2 = (ImageView) convertView.findViewById(R.id.icon2);
			convertView.setTag(v);
		} else {
			v = (ViewHodler) convertView.getTag();
		}
		if (list.getProjectList().get(position).isSelect()) {
			v.content.setTextColor(Color.parseColor("#f87242"));
			v.icon2.setVisibility(View.VISIBLE);
			v.icon1.setImageResource(R.drawable.ioc_1_cose);
		} else {
			v.content.setTextColor(Color.parseColor("#494949"));
			v.icon2.setVisibility(View.INVISIBLE);
			v.icon1.setImageResource(R.drawable.iocn_project1);
		}
		v.icon1.setVisibility(type == 1 ? View.GONE : View.VISIBLE);
		v.content.setText(list.getProjectList().get(position).getProjectName());
		return convertView;
	}

	public static class ViewHodler {
		/** 项目名称 */
		TextView content;

		ImageView icon1;

		ImageView icon2;

	}

}